package minijvm.cmd;

import minijvm.clz.ClassFile;

/**
 * @author ChangLiang
 * @date 2020/4/26
 */
public abstract class TwoOperandCmd extends ByteCodeCommand {

    int oprand1 = -1;
    int oprand2 = -1;

    public int getOprand1() {
        return oprand1;
    }

    public void setOprand1(int oprand1) {
        this.oprand1 = oprand1;
    }

    public int getOprand2() {
        return oprand2;
    }

    public void setOprand2(int oprand2) {
        this.oprand2 = oprand2;
    }

    public TwoOperandCmd(ClassFile clzFile, String opCode) {
        super(clzFile, opCode);
    }

    /**
     * 获取常量池索引
     * @return
     */
    public int getIndex() {
        int oprand1 = this.getOprand1();
        int oprand2 = this.getOprand2();
        int index = oprand1 << 8 | oprand2;
        return index;
    }

    @Override
    public int getLength() {
        return 3;
    }
}
